﻿using System;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using DMS.Common.Extensions;
using DMS.Common.Model.Result;
using DMS.Redis;
using Google.Protobuf.WellKnownTypes;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MySqlX.XDevAPI.Common;
using SqlSugar;
using SqlSugar.Template.Extensions;
using SqlSugar.Template.IService;
using SqlSugar.Template.IService.Param;
using SqlSugar.Template.IService.Result;
using SqlSugar.Template.Models;
using SqlSugar.Template.Service;

namespace BookApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {

        private readonly IUseService useService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="useService"></param>
        public UserController(IUseService useService)
        {
            this.useService =useService;       
        }

        [HttpPost("Add")]
        [Authorize]
        public async Task<ResponseResult> AddAsync(AddUseParam param)
        {
            var result = await useService.Add(param);
            return result;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id">自增主键</param>
        /// <returns></returns>
        [HttpPost("Delete")]
        [Authorize]

        public async Task<ResponseResult> DeleteAsync(long Id)
        {
            var result = await useService.DeleteAsync(Id);
            return result;
        }


        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="book"></param>
        /// <returns></returns>
        [HttpPost("Update")]
        [Authorize]
        public async Task<ResponseResult> UpdateAsync(EditUseParam param)
        {
            var result = await useService.UpdateAsync(param);
            return result;
        }
        [HttpGet("SearchUse")]
        [Authorize]
        public async Task<ResponseResult<PageModel<UseResult>>> SearchUseAsync([FromQuery] SearchUseParam param)
        {          
        var      result =await useService.SearchUseAsync(param);
            return result;
        }
    }
}
